package cate.game.role.res.call.advance;

import cate.common.table.d.GDHeroCall;
import cate.game.role.Role;
import cate.game.role.res.call.CallBasePO;
import cate.game.role.res.call.CallManager;
import cate.game.role.res.call.CallTool;
import cate.game.role.res.call.base.CallProcessData;
import cate.game.role.res.call.base.ICallExe;
import cate.game.role.res.call.base.ICallHandler;

import java.util.Set;


public class CallAdvanceCallPO extends CallBasePO implements ICallExe {

    @Override
    public void initialize(Role role, CallTool tool) {
        super.initialize(role, tool);
        role.getRes().callPO.register(getMode(), this);
    }

    public CallAdvanceCallPO() {
    }

    @Override
    protected void handlerRegister() {
        Set<Integer> typeSet = role.getGame().table.call.base.getModeAllType(getMode());
        typeSet.forEach(type -> CallManager.register(type, CallManager.advanceHandler));
    }

    @Override
    public void modifyByMods(Role role, CallProcessData processData, ICallHandler handler, CallBasePO basePO) {
        tool.addAllScore(role, processData);
        tool.ensureFiveHeroPool(role, processData, basePO);
        tool.randomDup(role, processData);
        ICallExe.super.modifyByMods(role, processData, handler, basePO);
    }

    @Override
    protected byte getMode() {
        return GDHeroCall.Mode.ADVANCE;
    }

    @Override
    protected void noticeUpdate(Role role) {
        role.getRes().callPO.noticeCallDataUpdate();
    }

    @Override
    public void handleResult(Role role, CallProcessData processData, ICallHandler handler, CallBasePO po) {
        if (!handler.calcResult(role, processData, po).ok()) {
            return;
        }
        tool.updatePo(role, processData, po);
        tool.sacrificeHero(role, processData);
        tool.sendResultToRole(role, processData);
        tool.sendHeroCallResp(role, processData, po);
        tool.lampOnline(role, processData);
        noticeUpdate(role);
    }

    @Override
    public CallAdvanceCallPO onGotPO(Role role) {
        return role.getRes().callPO.advance;
    }

}
